/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hitechbangla.fctu.utility;

import com.hitechbangla.fctu.base.GameScene;
import com.hitechbangla.fctu.base.Location;
import com.hitechbangla.fctu.base.aircraft.Aircraft;
import com.hitechbangla.fctu.base.aircraft.AircraftState;
import com.hitechbangla.fctu.base.aircraft.AircraftType;
import fctu.simulator.HTB_MAIN;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.openstreetmap.gui.jmapviewer.OsmMercator;

public class MultipleAircraft {
    
    private List<Aircraft> multipleAircraftList;   
    
    public void add()
    {
       
    }
    
    
    public MultipleAircraft(Rectangle2D.Double rectangle)
    {
        multipleAircraftList = new ArrayList<Aircraft>();
        Random random = new Random();
        AircraftType aircraftType1 = AircraftType.getAllAircraftType().get(0);
        AircraftType aircraftType2 = AircraftType.getAllAircraftType().get(1);
        
        for(int i=0;i<15;i++)
        {
            int a = 500;
            int b = i+1;
            String callsign = Integer.toString(a+b);
            float heading = random.nextInt(359);
           // float heading = 90;
            float speed = 1000 + random.nextInt(1000);
            //double newAircraftx = (double)(rectangle.x + random.nextDouble(rectangle.width));
            double randomX = (double)random.nextInt((int)rectangle.width);
            double randomY = (double)random.nextInt((int)rectangle.height)/50;;
            
            double newAircraftx = rectangle.x + randomX;
            double newAircrafty = rectangle.y + randomY;
            //double newAircrafty = rectangle.y + random.nextInt(rectangle.height);
             float height = random.nextInt(2000);
            
            double fLon =(newAircraftx);
            double fLat =(newAircrafty);
            
            int fX = OsmMercator.LonToX(fLon, HTB_MAIN.currentZoom);
            int fY = OsmMercator.LatToY(fLat, HTB_MAIN.currentZoom);
            
            double x = (fX - HTB_MAIN.translate_x);
	    double y = (-fY + HTB_MAIN.translate_y);
            
            Location location = new Location(x*HTB_MAIN.gameScene.HTBParent.one_nm_equivalent_pixel, y*HTB_MAIN.gameScene.HTBParent.one_nm_equivalent_pixel,0);
            //Location location = new Location(-178.8134765625, 84.6989485806069,0);
            AircraftState aircraftState = new AircraftState(callsign,location,heading,speed,height);
            Aircraft aircraft = new Aircraft(aircraftState,aircraftType1);
            
            multipleAircraftList.add(aircraft);
        }
        
        for(int i=15;i<30;i++)
        {
            int a =500;
            int b = i+1;
            String callsign = Integer.toString(a+b);
            float heading = random.nextInt(359);
            float speed = 1000 + random.nextInt(1000);
            double newAircraftx = rectangle.x + (double)random.nextInt((int)rectangle.width);
            double newAircrafty = rectangle.y + (double)random.nextInt((int)rectangle.height);
           // float newAircraftx = rectangle.x + random.nextInt(rectangle.width);
           // float newAircrafty = rectangle.y + random.nextInt(rectangle.height);
            float height = random.nextInt(2000);
            
            double fLon =(newAircraftx);
            double fLat =(newAircrafty);
            
            int fX = OsmMercator.LonToX(fLon, HTB_MAIN.currentZoom);
            int fY = OsmMercator.LatToY(fLat, HTB_MAIN.currentZoom);
            
            double x = (fX - HTB_MAIN.translate_x);
	    double y = (-fY + HTB_MAIN.translate_y);
            Location location = new Location(x*HTB_MAIN.gameScene.HTBParent.one_nm_equivalent_pixel, y*HTB_MAIN.gameScene.HTBParent.one_nm_equivalent_pixel,0);
            
            //Location location = new Location(newAircraftx, newAircrafty,0);
            AircraftState aircraftState = new AircraftState(callsign,location,heading,speed,height);
            Aircraft aircraft = new Aircraft(aircraftState,aircraftType2);
            
            multipleAircraftList.add(aircraft);
             
        }
        
        
       
       // 
        //multipleAircraftList.add(aircraftType1);
      
    
    }
    
    public static void main(String a[])
    {
        Rectangle2D.Double rectangle = new Rectangle2D.Double(-174.48486328125,84.08887757413991, 4,10);
        MultipleAircraft multipleAircraft = new MultipleAircraft(rectangle);              
        
    } 

    /**
     * @return the multipleAircraftList
     */
    public List<Aircraft> getMultipleAircraftList() {
        return multipleAircraftList;
    }
    
}
